Skip to content

task#342

Open
iryna-knyzh wants to merge 2 commits intomate-academy:masterfrom
iryna-knyzh:develop
Open

task#342
iryna-knyzh wants to merge 2 commits intomate-academy:masterfrom
iryna-knyzh:develop

Conversation

@iryna-knyzh
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Great job implementing the core logic for moving and renaming files! The way you handle different destination types is well-structured. However, this submission requires changes due to a critical error handling issue that causes the application to crash.

In src/app.js, when the destination path ends with a / but the directory does not exist, the await fs.stat(destination) call on line 36 throws an error that isn't caught. This results in an unhandled promise rejection, crashing the program instead of displaying a clean error message as required.

Please wrap the logic within the if (lastChar === '/') block in a try...catch statement to handle this potential error gracefully. This will ensure your application is robust and meets all the requirements.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines 35 to 42
if (lastChar === '/') {
const stat = await fs.stat(destination);

if (!stat.isDirectory()) {
throw new Error('directory not exists');
}

newDestination = destination + path.basename(source);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block has some issues with error handling. The await fs.stat(destination) call on line 36 will throw an error if the path doesn't exist. Additionally, the throw new Error(...) on line 39 is not caught anywhere. Both of these scenarios will cause an unhandled promise rejection and crash the application. This logic should be wrapped in a try...catch block to handle potential errors gracefully and provide a clear error message to the user, similar to how you handle the error for the fs.rename call.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Excellent work on this revision! I'm happy to approve your solution. You've successfully addressed the critical error-handling issue, and the application now gracefully handles cases where the destination directory doesn't exist, preventing any crashes. The new isDirectoryExists helper function is a great addition that makes the code much cleaner and more readable. Your implementation now meets all the requirements perfectly. Well done!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants